home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1999 #2 / Amiga Plus CD - 1999 - No. 2.iso / System-Boost / Workbench / TinyMeter / Source / TinyMeter_main / handler.c < prev    next >
C/C++ Source or Header  |  1997-02-27  |  25KB  |  792 lines

  1. #include <intuition/classusr.h>
  2. #include <intuition/gadgetclass.h>
  3. #include <intuition/cghooks.h>
  4. #include <intuition/icclass.h>
  5. #include <intuition/classes.h>
  6. #include <utility/tagitem.h>
  7. #include <exec/types.h>
  8. #include <exec/memory.h>
  9. #include <dos/dos.h>
  10. #include <exec/types.h>
  11. #include <exec/memory.h>
  12. #include <dos/notify.h>
  13. #include <intuition/intuition.h>
  14. #include <libraries/SysInfo.h>
  15. #include <utility/tagitem.h>
  16. #include <clib/macros.h>
  17. #include <libraries/commodities.h>
  18. #include <libraries/ScreenNotify.h>
  19. #include <datatypes/datatypesclass.h>
  20. #include <datatypes/datatypes.h>
  21. #include <datatypes/pictureclass.h>
  22. #include <workbench/workbench.h>
  23. #include <workbench/startup.h>
  24. #include "gaugeclass.h"
  25. #include "launchclass.h"
  26. #include "tinymeter.h"
  27.  
  28. #define test_test       0
  29. #define test_getwin     1
  30.  
  31. #define do_clock        1
  32. #define do_mem          2
  33. #define do_vol          3
  34.  
  35. struct TestMessage
  36. {
  37.     struct  Message ts_Message;
  38.     ULONG   MethodID;
  39.     struct  tm_sys_set  *set;
  40.     struct  tm_gau_set  *list;
  41.     ULONG   posx,
  42.         posy,
  43.         sizx;
  44. };
  45.  
  46. void init_time_request(struct timerequest *my_time_request_clock, ULONG my_time_mask_clock)
  47. {
  48.     ULONG interval;
  49.     my_time_request_clock -> tr_node.io_Command     = TR_GETSYSTIME;
  50.     DoIO((struct IORequest *)my_time_request_clock);
  51.     interval=my_time_request_clock -> tr_time.tv_secs;
  52.     my_time_request_clock -> tr_node.io_Command     = TR_ADDREQUEST;
  53.     my_time_request_clock -> tr_time.tv_secs        = interval+1;
  54.     my_time_request_clock -> tr_time.tv_micro       = NULL;
  55.     SetSignal(NULL,my_time_mask_clock);
  56.     SendIO((struct IORequest *)my_time_request_clock);
  57. }
  58.  
  59. ULONG snapSub(struct tm_sys_set *set, struct tm_data *data)
  60. {
  61.     struct lau_enty         *list;
  62.     int                     i;
  63.     struct IntuiMessage     *m;
  64.  
  65.     while((m=(struct IntuiMessage *)GetMsg( data->win->UserPort ))) ReplyMsg( (struct Message *)m );
  66.     data->win=(struct Window *) snapBackground(set,data);
  67.                 drawBackground(set,data);
  68.     for(i=NULL;i<data->num_of_gaug;i++)
  69.     {
  70.     if(data->gdg[i])
  71.     {
  72.         GetAttr(LAU_List,data->gdg[i],(ULONG *)&list);
  73.         if(list) AddGList(data->win,data->gdg[i],0,1,NULL);
  74.         else     AddGList(data->win,data->gdg[i],-1,1,NULL);
  75.         SetAttrs(data->gdg[i],GA_Width, data->gauge_x_size, NULL);
  76.     }
  77.     }
  78.     RefreshGList(data->win->FirstGadget,data->win,NULL,-1);
  79.     return((ULONG)1L << data->win->UserPort->mp_SigBit);
  80. }
  81.  
  82. void setBase(struct tm_data *data)
  83. {
  84.     int                 i;
  85.     ULONG               cur;
  86.     for(i=NULL;i<data->num_of_gaug;i++)
  87.     {
  88.     if(data->gdg[i])
  89.     {
  90.         GetAttr(GAU_Current,data->gdg[i],&cur);
  91.         SetAttrs(data->gdg[i],GAU_Current,cur,GAU_Base,cur,TAG_DONE);
  92.     }
  93.     }
  94.     RefreshGList(data->win->FirstGadget,data->win,NULL,-1);
  95. }
  96.  
  97. void handle_launcher(struct tm_data *data, WORD ID, struct Gadget *obj,struct WBArg *wbarg, ULONG numarg)
  98. {
  99.     struct  Window          *lwin;
  100.     struct  RastPort        *rp,
  101.                 tmpras;
  102.     BOOL                    foo=TRUE,
  103.                 start=FALSE;
  104.     struct  lau_entry       *entry,
  105.                 *foobar;
  106.     LONG                    dummy,
  107.                 height,
  108.                 width;
  109.     LONG                    x,
  110.                 y,
  111.                 selected,
  112.                 sigs,
  113.                 lastsel;
  114.     ULONG                   pen_bg,
  115.                 pen_bright,
  116.                 pen_dark,
  117.                 pen_cur,
  118.                 pen_entry,
  119.                 window_mask,
  120.                 lwindow_mask,
  121.                 down,trans;
  122.     UWORD                   entryheight,
  123.                 iw=NULL,
  124.                 y_pos;
  125.     struct IntuiMessage     *m;
  126.     struct BitMapHeader     *bmhd;
  127.     struct MsgPort          *appport;
  128.     struct AppWindow        *appwin;
  129.     ULONG                    appwinsig;
  130.  
  131.     GetAttr(LAU_ColEntry     ,obj,(ULONG *)&pen_entry);
  132.     GetAttr(LAU_ColBrightEdg ,obj,(ULONG *)&pen_bright);
  133.     GetAttr(LAU_ColDarkEdg   ,obj,(ULONG *)&pen_dark);
  134.     GetAttr(LAU_ColBackground,obj,(ULONG *)&pen_bg);
  135.     GetAttr(LAU_ColCursor    ,obj,(ULONG *)&pen_cur);
  136.     GetAttr(LAU_List         ,obj,(ULONG *)&entry);
  137.     GetAttr(LAU_Down         ,obj,(ULONG *)&down);
  138.     GetAttr(LAU_Transparent  ,obj,(ULONG *)&trans);
  139.     if((foobar=entry)&&(ID>-1))
  140.     {
  141.     InitRastPort(&tmpras);
  142.     SetFont(&tmpras,data->Font[ID]);
  143.     dummy=NULL;
  144.     entryheight=data->Font[ID]->tf_YSize;
  145.     width=data->gdg[ID]->Width+2;
  146.     do
  147.     {
  148.         if(foobar->img)
  149.         {
  150.         GetDTAttrs(foobar->img,PDTA_BitMapHeader,(ULONG *)&bmhd,TAG_DONE);
  151.         if(bmhd)
  152.         {
  153.             entryheight=MAX(entryheight,bmhd->bmh_Height+2);
  154.             iw=MAX(iw,bmhd->bmh_Width+6);
  155.         }
  156.         }
  157.         foobar->width=TextLength(&tmpras,foobar->lau_lbl,my_strlen(foobar->lau_lbl));
  158.         width=MAX(width,foobar->width+12+iw);
  159.         dummy++;
  160.     }
  161.     while(foobar=foobar->next);
  162.  
  163.     y_pos=((entryheight-((data->Font[ID]->tf_Baseline+data->Font[ID]->tf_YSize)>>1))>>1);
  164.     if(data->Font[ID]->tf_Baseline<data->Font[ID]->tf_YSize)
  165.     {
  166.         y_pos+=data->Font[ID]->tf_Baseline-1;
  167.         if(y_pos<data->Font[ID]->tf_Baseline)y_pos=data->Font[ID]->tf_Baseline;
  168.     }
  169.     else
  170.     {
  171.         y_pos+=data->Font[ID]->tf_YSize-1;
  172.         if(y_pos<data->Font[ID]->tf_YSize)   y_pos=data->Font[ID]->tf_YSize;
  173.     }
  174.  
  175.     height=(entryheight*dummy)+2;
  176.     y=data->gdg[ID]->TopEdge+data->win->TopEdge-( down==lau_up ? height : ( down== lau_down ? -data->gdg[ID]->Height : height>>1 ));
  177.     if((lwin=(struct Window *)OpenWindowTags(NULL,
  178.         WA_Left,            data->gdg[ID]->LeftEdge+data->win->LeftEdge-1,
  179.         WA_Top,             y,
  180.         WA_Width,           width,
  181.         WA_Height,          height,
  182.         WA_Flags,           WFLG_BORDERLESS|WFLG_REPORTMOUSE|WFLG_RMBTRAP|WFLG_ACTIVATE,
  183.         WA_PubScreen,       data->scr,
  184.         WA_IDCMP,           IDCMP_MOUSEBUTTONS|IDCMP_MOUSEMOVE,
  185.         TAG_END)))
  186.     {
  187.         if(appport=(struct MsgPort *)CreateMsgPort())
  188.         {
  189.         appwin=(struct AppWindow *)AddAppWindow(0L, 0L, lwin, appport , 0L);
  190.         appwinsig= 1L << appport->mp_SigBit;
  191.         }
  192.         selected     =-1;
  193.         lastsel      =-1;
  194.         window_mask  = 1L << data->win->UserPort->mp_SigBit;
  195.         lwindow_mask = 1L << lwin->UserPort->mp_SigBit;
  196.  
  197.         SetFont(rp=lwin->RPort,data->Font[ID]);
  198.         SetAPen(rp,pen_bg); RectFill(rp,0,0,width-1,height-1);
  199.         draw_border_new(rp,0,0,width,height,pen_bright,pen_dark);
  200.         SetAPen(rp,pen_entry);
  201.         SetDrMd(rp,JAM1);
  202.         foobar=entry;
  203.         dummy=0;
  204.         do
  205.         {
  206.         if(foobar->img)
  207.         {
  208.             GetDTAttrs(foobar->img,PDTA_BitMapHeader,&bmhd,TAG_DONE);
  209.             DrawDTObject(foobar->img,0,0,rp,2+((iw-bmhd->bmh_Width)>>1),(dummy*entryheight)+1+((entryheight-bmhd->bmh_Height)>>1),-1,-1,trans);
  210.         }
  211.         Move(rp,iw+7,((dummy++)*entryheight)+y_pos+1);
  212.         Text(rp,foobar->lau_lbl,my_strlen(foobar->lau_lbl));
  213.         }
  214.         while(foobar=foobar->next);
  215.         while(foo)
  216.         {
  217.         sigs=Wait( window_mask | lwindow_mask | appwinsig );
  218.         if(sigs & appwinsig)
  219.         {
  220.             struct AppMessage *apm;
  221.             while(apm=(struct AppMessage *)GetMsg(appport))
  222.             {
  223.             selected=(apm->am_MouseY-1)/entryheight;
  224.             for(foobar=entry,dummy=0;dummy<selected;dummy++)foobar=foobar->next;
  225.             if(apm->am_Type==AMTYPE_APPWINDOW)
  226.             {
  227.                 RunFile(foobar,data,apm->am_ArgList,apm->am_NumArgs);
  228.             }
  229.             ReplyMsg((struct Message *)apm);
  230.             }
  231.         }
  232.         if(sigs & window_mask)
  233.         {
  234.             while(m=(struct IntuiMessage *)GetMsg(data->win->UserPort))
  235.             {
  236.             switch (m->Class)
  237.             {
  238.                 case    IDCMP_GADGETDOWN:
  239.                     foo=FALSE;
  240.                     break;
  241.             }
  242.             ReplyMsg((struct Message *)m);
  243.             }
  244.         }
  245.         if(sigs & lwindow_mask)
  246.         {
  247.             while(m=(struct IntuiMessage *)GetMsg(lwin->UserPort))
  248.             {
  249.             switch (m->Class)
  250.             {
  251.                 case    IDCMP_MOUSEBUTTONS:
  252.                     if((m->Code&15)==8)
  253.                     {
  254.                     selected=(m->MouseY-1)/entryheight;
  255.                     foo=FALSE;
  256.                     start=TRUE;
  257.                     }
  258.                     break;
  259.                 case    IDCMP_MOUSEMOVE:
  260.                     x=m->MouseX;
  261.                     y=m->MouseY;
  262.                     if((x>0)&&(y>0)&&(x<(width-1))&&(y<(height-1)))
  263.                     {
  264.                     selected=(y-1)/entryheight;
  265.                     if(selected!=lastsel)
  266.                     {
  267.                         if(lastsel!=-1)
  268.                         {
  269.                         SetAPen(rp,pen_bg);
  270.                         RectFill(rp,iw+3,1+(lastsel*entryheight),width-4,((lastsel+1)*entryheight));
  271.                         SetAPen(rp,pen_entry);
  272.                         for(foobar=entry,dummy=0;dummy<lastsel;dummy++)foobar=foobar->next;
  273.                         Move(rp,iw+7,(lastsel*entryheight)+y_pos+1);
  274.                         Text(rp,foobar->lau_lbl,my_strlen(foobar->lau_lbl));
  275.                         }
  276.                         SetAPen(rp,pen_cur);
  277.                         RectFill(rp,iw+3,1+(selected*entryheight),width-4,((selected+1)*entryheight));
  278.                         SetAPen(rp,pen_entry);
  279.                         for(foobar=entry,dummy=0;dummy<selected;dummy++)foobar=foobar->next;
  280.                         Move(rp,iw+7,(selected*entryheight)+y_pos+1);
  281.                         Text(rp,foobar->lau_lbl,my_strlen(foobar->lau_lbl));
  282.                     }
  283.                     lastsel=selected;
  284.                     }
  285.                     else
  286.                     {
  287.                     if(lastsel!=-1)
  288.                     {
  289.                         SetAPen(rp,pen_bg);
  290.                         RectFill(rp,iw+1,1+(lastsel*entryheight),width-2,((lastsel+1)*entryheight));
  291.                         SetAPen(rp,pen_entry);
  292.                         for(foobar=entry,dummy=0;dummy<lastsel;dummy++)foobar=foobar->next;
  293.                         Move(rp,iw+7,(lastsel*entryheight)+y_pos+1);
  294.                         Text(rp,foobar->lau_lbl,my_strlen(foobar->lau_lbl));
  295.                     }
  296.                     selected=-1;
  297.                     lastsel=-1;
  298.                     }
  299.                     break;
  300.             }
  301.             ReplyMsg((struct Message *)m);
  302.             }
  303.         }
  304.         }
  305.         while(m=(struct IntuiMessage *)GetMsg(data->win->UserPort))ReplyMsg((struct Message *)m);
  306.         while(m=(struct IntuiMessage *)GetMsg(lwin->UserPort))     ReplyMsg((struct Message *)m);
  307.  
  308.         if(appwin)  RemoveAppWindow(appwin);
  309.         if(appport) DeletePort(appport);
  310.  
  311.         CloseWindow(lwin);
  312.         if(start&&(selected>-1))
  313.         {
  314.         for(foobar=entry,dummy=0;dummy<selected;dummy++)foobar=foobar->next;
  315.         RunFile(foobar,data,wbarg,numarg);
  316.         }
  317.     }
  318.     else DisplayBeep(0);
  319.     }
  320. }
  321.  
  322. struct tm_sys_set *handler(struct tm_sys_set *set, struct tm_data *data, struct MsgPort *broker_mp, CxObj *broker, ULONG cxsigflag, Class *gclass, Class *lclass)
  323. {
  324.     BOOL                        running = TRUE;
  325.  
  326.     ULONG                       mem_val=0,
  327.                 vol_val=0,
  328.                 sigs,
  329.                 window_mask,
  330.                 my_time_mask_clock,
  331.                 my_test_port_mask,
  332.                 my_noti_port_mask=0L,
  333.                 my_app_port_mask =0L,
  334.                 my_handler;
  335.  
  336.     struct MsgPort             *my_time_port_clock,
  337.                    *my_test_port,
  338.                    *my_noti_port;
  339.  
  340.     struct timerequest         *my_time_request_clock;
  341.  
  342.     struct NotifyRequest       *notifyrequest;
  343.     LONG                        not_sig;
  344.     BOOL                        closed=FALSE;
  345.  
  346.     struct IntuiMessage        *m;
  347.     int                         i;
  348.     struct TestMessage         *test_msg;
  349.     struct tm_gau_set          *many,*next;
  350.     BOOL                        first_run=TRUE,doit;
  351.     UWORD                       do_what;
  352.  
  353.     if(data->scrnot)
  354.     {
  355.     my_noti_port        = (struct MsgPort *)CreateMsgPort();
  356.     my_handler          = ((!data->on_public)|(!strcmp(&set->pub_name[0],"Workbench"))) ? (ULONG)AddWorkbenchClient(my_noti_port,0) : (ULONG)AddCloseScreenClient(data->scr,my_noti_port,0);
  357.     my_noti_port_mask   = 1L << my_noti_port->mp_SigBit;
  358.     }
  359.  
  360.     if(data->appwin) my_app_port_mask    = 1L << data->appport->mp_SigBit;
  361.  
  362.     window_mask  = 1L << data->win->UserPort->mp_SigBit;
  363.  
  364.     if(my_test_port=(struct MsgPort *)CreatePort("TinyMeter",0))
  365.     {
  366.     my_test_port_mask = 1L << (my_test_port->mp_SigBit);
  367.     if(my_time_port_clock=(struct MsgPort *)CreateMsgPort())
  368.     {
  369.         my_time_mask_clock    = 1L << (my_time_port_clock->mp_SigBit);
  370.         if(my_time_request_clock = (struct timerequest *)CreateIORequest(my_time_port_clock,sizeof(struct timerequest)))
  371.         {
  372.         if(!OpenDevice("timer.device",UNIT_WAITUNTIL,(struct IORequest *)my_time_request_clock,NULL))
  373.         {
  374.             if(notifyrequest = (struct NotifyRequest *)pAllocVec(sizeof(struct NotifyRequest)))
  375.             {
  376.             if ((not_sig = AllocSignal(-1L)) != -1)
  377.             {
  378.                 notifyrequest->nr_Name                          = "ENV:Sys/WBPattern.prefs";
  379.                 notifyrequest->nr_Flags                         = NRF_SEND_SIGNAL;
  380.                 notifyrequest->nr_stuff.nr_Signal.nr_Task       = (struct Task *) FindTask(NULL);
  381.                 notifyrequest->nr_stuff.nr_Signal.nr_SignalNum  = not_sig;
  382.                 if((StartNotify(notifyrequest))==DOSTRUE)
  383.                 {
  384.                 init_time_request(my_time_request_clock,my_time_mask_clock);
  385.                 while(running)
  386.                 {
  387.                     sigs = Wait( my_noti_port_mask | my_test_port_mask | window_mask | my_time_mask_clock | (1L << not_sig) | cxsigflag | my_app_port_mask );
  388.                     if(!closed)
  389.                     {
  390.                     if (sigs & my_time_mask_clock)
  391.                     {
  392.                         WaitIO((struct IORequest *)my_time_request_clock);
  393.                         init_time_request(my_time_request_clock,my_time_mask_clock);
  394.                         do_what=do_clock;
  395.                         mem_val++;
  396.                         if(mem_val>=set->mem_refresh)
  397.                         {
  398.                         mem_val=0;
  399.                         do_what=do_mem;
  400.                         }
  401.                         vol_val++;
  402.                         if(vol_val>=set->vol_refresh)
  403.                         {
  404.                         vol_val=0;
  405.                         do_what=do_vol;
  406.                         }
  407.                         for(i=0,many=data->list;i<data->num_of_gaug;i++,many=many->next)
  408.                         {
  409.                         doit=FALSE;
  410.                         if(data->gdg[i])                                     
  411.                         switch (do_what)
  412.                         {
  413.                             case    do_vol:
  414.                                 if(many->type==typ_volume) { doit=TRUE; break; }
  415.                             case    do_mem:
  416.                                 if((many->type!=typ_none)&&(many->type!=typ_iconlauncher)&&(many->type!=typ_simplelauncher)&&(many->type!=typ_volume)) { doit=TRUE; break; }
  417.                             default:
  418.                                 if(many->type==typ_clock_) doit=TRUE;
  419.                                 break;
  420.                         }                                                                
  421.                         if(doit) DoMethod((Object *)data->gdg[i],MY_REFRESH,data->win,NULL);
  422.                         }
  423.                         if(first_run){setBase(data);first_run=FALSE;}
  424.                         if(set->win_backfront==win_front) if(data->win->WLayer!=data->scr->LayerInfo.top_layer) WindowToFront(data->win);
  425.                     }
  426.                     if (sigs & my_app_port_mask)
  427.                     {
  428.                         struct AppMessage *appmsg;
  429.                         while(appmsg=(struct AppMessage *)GetMsg( data->appport))
  430.                         {
  431.                         if(appmsg->am_Type=AMTYPE_APPWINDOW)
  432.                         {
  433.                             for(i=0,many=data->list;i<data->num_of_gaug;i++,many=many->next)
  434.                             {
  435.                             if((many->type==typ_simplelauncher)||(many->type==typ_iconlauncher))
  436.                             if(data->gdg[i])
  437.                             {
  438.                                 if((data->gdg[i]->TopEdge <appmsg->am_MouseY)&&((data->gdg[i]->TopEdge +data->gdg[i]->Height)>appmsg->am_MouseY)&&
  439.                                    (data->gdg[i]->LeftEdge<appmsg->am_MouseX)&&((data->gdg[i]->LeftEdge+data->gdg[i]->Width) >appmsg->am_MouseX)
  440.                                 )
  441.                                 {
  442.                                 if(data->gdg[i]->GadgetID<0xFFF0)
  443.                                 {
  444.                                     struct lau_entry    *entry;
  445.                                     GetAttr(LAU_List,(Object *)data->gdg[i],(ULONG *)&entry);
  446.                                     if(many->type==typ_simplelauncher)
  447.                                     {
  448.                                     if(entry->next) handle_launcher (data,(UWORD)data->gdg[i]->GadgetID,(struct Gadget *)data->gdg[i],appmsg->am_ArgList,appmsg->am_NumArgs);
  449.                                     else            RunFile         (entry,data,appmsg->am_ArgList,appmsg->am_NumArgs);
  450.                                     }
  451.                                     else
  452.                                     {
  453.                                     ULONG               fullness;
  454.                                     struct BitMapHeader *bmhd;
  455.                                     WORD                x=appmsg->am_MouseX-data->gdg[i]->LeftEdge;
  456.                                     GetAttr(LAU_XPos,(Object *)data->gdg[i],&fullness);
  457.                                     if(entry)
  458.                                     {
  459.                                         do
  460.                                         {
  461.                                         if(entry->img)
  462.                                         {
  463.                                             GetDTAttrs(entry->img,PDTA_BitMapHeader,&bmhd,TAG_DONE);
  464.                                             if(bmhd)
  465.                                             {
  466.                                             if(((fullness+bmhd->bmh_Width)>x)&&(fullness<x)) break;
  467.                                             fullness+=bmhd->bmh_Width;
  468.                                             }
  469.                                         }
  470.                                         }
  471.                                         while(entry=entry->next);
  472.                                         RunFile(entry,data,appmsg->am_ArgList,appmsg->am_NumArgs);
  473.                                     }
  474.                                     }
  475.                                 }
  476.                                 }
  477.                             }
  478.                             }
  479.                         }
  480.                         ReplyMsg((struct Message *)appmsg);
  481.                         }
  482.                     }
  483.                     if (sigs & window_mask)
  484.                     {
  485.                         while(m=(struct IntuiMessage *)GetMsg( data->win->UserPort ))
  486.                         {
  487.                         switch ( m->Class )
  488.                         {
  489.                             case    IDCMP_GADGETDOWN:
  490.                                 {
  491.                                 WORD    x;
  492.                                 struct Gadget *g=((struct Gadget *)(m->IAddress));
  493.                                 x=m->MouseX-g->LeftEdge;
  494.                                 ReplyMsg((struct Message *)m);
  495.                                 if(g->GadgetID<0xFFF0)
  496.                                 {
  497.                                     struct lau_entry    *entry;
  498.                                     ULONG               type;
  499.                                     GetAttr(LAU_List,(Object *)g,(ULONG *)&entry);
  500.                                     GetAttr(LAU_Type,g,&type);
  501.                                     if(type==typ_iconlauncher)
  502.                                     {
  503.                                     ULONG   fullness;
  504.                                     struct  BitMapHeader *bmhd;
  505.                                     GetAttr(LAU_XPos,(Object *)g,&fullness);
  506.                                     if(entry)
  507.                                     {
  508.                                         do
  509.                                         {
  510.                                         if(entry->img)
  511.                                         {
  512.                                             GetDTAttrs(entry->img,PDTA_BitMapHeader,&bmhd,TAG_DONE);
  513.                                             if(bmhd)
  514.                                             {
  515.                                             if((x<(fullness+bmhd->bmh_Width))&&(x>fullness)) break;
  516.                                             fullness+=bmhd->bmh_Width;
  517.                                             }
  518.                                         }
  519.                                         }
  520.                                         while(entry=entry->next);
  521.                                         RunFile(entry,data,NULL,NULL);
  522.                                     }
  523.                                     }
  524.                                     else if(entry->next)  handle_launcher(data,(UWORD)g->GadgetID,(struct Gadget *)g,NULL,NULL);
  525.                                     else                  RunFile(entry,data,NULL,NULL);
  526.                                 }
  527.                                 }
  528.                                 break;
  529.                             case    IDCMP_CHANGEWINDOW:
  530.                                 ReplyMsg((struct Message *)m);
  531.                                 if(set->bg_type==bg_snap) window_mask=snapSub(set,data);
  532.                                 break;
  533.                             case    IDCMP_CLOSEWINDOW:
  534.                                 running=FALSE;
  535.                                 ReplyMsg((struct Message *)m);
  536.                                 break;
  537.                             case    IDCMP_NEWSIZE:
  538.                                 ReplyMsg((struct Message *)m);
  539.                                 new_window_size(set,data);
  540.                                 set->x_siz=data->win->Width;
  541.                                 data->gauge_x_size=(set->x_siz-(set->win_border_x<<1)-((set->colums-1)*set->win_space_x))/set->colums;
  542.                                 if(set->bg_type==bg_file) fileBackground(set,data);
  543.                                 drawBackground(set,data);
  544.                                 for(i=0;i<data->num_of_gaug;i++) if(data->gdg[i]) SetAttrs(data->gdg[i],GA_Left,set->win_border_x+((i)%set->colums)*data->gauge_x_size+((i)%set->colums)*set->win_space_x,GA_Width,data->gauge_x_size,TAG_DONE);
  545.                                 if(set->bg_type!=bg_snap)RefreshGList(data->win->FirstGadget,data->win,NULL,-1);
  546.                                 if(set->bg_type==bg_snap)window_mask=snapSub(set,data);
  547.                                 break;
  548.                             case    IDCMP_VANILLAKEY:
  549.                                 {
  550.                                 int Code=m->Code;
  551.                                 ReplyMsg((struct Message *)m);
  552.                                 switch(Code)
  553.                                 {
  554.                                     case    'S':
  555.                                     case    's':
  556.                                         {
  557.                                         BPTR my_file,my_file1;
  558.                                         set->x_pos=data->win->LeftEdge;
  559.                                         set->y_pos=data->win->TopEdge;
  560.                                         set->x_siz=data->win->Width;
  561.                                         my_file= (BPTR)Open("ENV:TinyMeter",   MODE_NEWFILE);
  562.                                         my_file1=(BPTR)Open("ENVARC:TinyMeter",MODE_NEWFILE);
  563.                                         if(my_file) Write(my_file, set,(ULONG) sizeof(struct tm_sys_set));
  564.                                         if(my_file1)Write(my_file1,set,(ULONG) sizeof(struct tm_sys_set));
  565.                                         many=data->list;
  566.                                         for(i=0;i<data->num_of_gaug;i++)
  567.                                         {
  568.                                             if(my_file) Write(my_file, many,(ULONG) sizeof(struct tm_gau_set));
  569.                                             if(my_file1)Write(my_file1,many,(ULONG) sizeof(struct tm_gau_set));
  570.                                             many=many->next;
  571.                                         }
  572.                                         if(my_file) Close(my_file1);
  573.                                         if(my_file1)Close(my_file);
  574.                                         }
  575.                                         break;
  576.                                     case    'F':
  577.                                     case    'f':
  578.                                         {
  579.                                         void *my_mem;
  580.                                         Forbid();
  581.                                         my_mem=AllocVec(2000000000L,MEMF_PUBLIC);
  582.                                         if(my_mem)FreeVec((APTR)my_mem);
  583.                                         Permit();
  584.                                         }
  585.                                         break;
  586.                                     case    'Q':
  587.                                     case    'q':
  588.                                         running=FALSE;
  589.                                         break;
  590.                                     case    'b':
  591.                                     case    'B':
  592.                                         if(set->bg_type==bg_snap)window_mask=snapSub(set,data);
  593.                                         break;
  594.                                 }
  595.                                 }
  596.                                 break;
  597.                             case    IDCMP_MOUSEBUTTONS:
  598.                                 if((m->Code&129)==1) setBase(data);
  599.                             default :
  600.                                 ReplyMsg((struct Message *)m);
  601.                                 break;
  602.                         }
  603.                         }
  604.                     }
  605.                     if (sigs & (1L << not_sig))
  606.                     {
  607.                         Delay(100L);
  608.                         if(set->bg_type==bg_snap) window_mask=snapSub(set,data);
  609.                     }
  610.                     }
  611.                     else if (sigs & my_time_mask_clock) init_time_request(my_time_request_clock,my_time_mask_clock);
  612.  
  613.                     if (sigs & cxsigflag)
  614.                     {
  615.                     CxMsg *msg;
  616.                     ULONG msgid, msgtype;
  617.  
  618.                     while(msg = (CxMsg *)GetMsg(broker_mp))
  619.                     {
  620.                         msgid   = CxMsgID(msg);
  621.                         msgtype = CxMsgType(msg);
  622.                         ReplyMsg((struct Message *)msg);
  623.                         if(msgtype==CXM_COMMAND)
  624.                         {
  625.                         switch(msgid)
  626.                         {
  627.                             case    CXCMD_DISABLE:
  628.                                 {
  629.                                 BOOL pause=TRUE;
  630.                                 ActivateCxObj(broker, 0L);
  631.                                 while(pause)
  632.                                 {
  633.                                     Wait(cxsigflag);
  634.                                     while(msg = (CxMsg *)GetMsg(broker_mp))
  635.                                     {
  636.                                     msgid = CxMsgID(msg);
  637.                                     msgtype = CxMsgType(msg);
  638.                                     ReplyMsg((struct Message *)msg);
  639.                                     if(msgtype==CXM_COMMAND) if(msgid==CXCMD_ENABLE) pause=FALSE;
  640.                                     }
  641.                                 }
  642.                                 ActivateCxObj(broker, 1L);
  643.                                 }
  644.                                 break;
  645.                             case    CXCMD_KILL:
  646.                                 running=FALSE;
  647.                             case    CXCMD_ENABLE:
  648.                                 ActivateCxObj(broker, 1L);
  649.                             default:
  650.                                 break;
  651.                         }
  652.                         }
  653.                     }
  654.                     }
  655.                     if ((sigs & my_test_port_mask)&&(!closed))
  656.                     {
  657.                     while(test_msg=(struct TestMessage *)GetMsg(my_test_port))
  658.                     {
  659.                         switch (test_msg->MethodID)
  660.                         {
  661.                         case    test_test:
  662.                             if(test_msg->set && test_msg->list)
  663.                             {
  664.                                 struct tm_gau_set *manyn,*nextn;
  665.                                 closeWindow(set,data);
  666.                                 first_run=TRUE;
  667.                                 pFreeVec((ULONG *)set);
  668.                                 many=data->list;
  669.                                 do
  670.                                 {
  671.                                 next=many->next;
  672.                                 pFreeVec((ULONG *)many);
  673.                                 }
  674.                                 while(many=next);
  675.  
  676.                                 if(set=(struct tm_sys_set *)pAllocVec(sizeof(struct tm_sys_set)))
  677.                                 {
  678.                                 CopyMem(test_msg->set,set,sizeof(struct tm_sys_set));
  679.                                 }
  680.                                 else running=FALSE;
  681.  
  682.                                 data->num_of_gaug   = getNum(test_msg->list);
  683.                                 many                = test_msg->list;
  684.                                 if(!(nextn=(struct tm_gau_set *)pAllocVec(sizeof(struct tm_gau_set)))){return(set);}
  685.                                 data->list          = nextn;
  686.  
  687.                                 for(i=0;i<data->num_of_gaug;i++)
  688.                                 {
  689.                                 manyn=nextn;
  690.                                 if(!(nextn=(struct tm_gau_set *)pAllocVec(sizeof(struct tm_gau_set)))){return(set);}
  691.                                 CopyMem(many,manyn,sizeof(struct tm_gau_set));
  692.                                 manyn->next=nextn;
  693.                                 many=many->next;
  694.                                 }
  695.                                 pFreeVec((ULONG *)nextn);
  696.                                 manyn->next=NULL;
  697.                                 if(openWindow(set,data,gclass,lclass))
  698.                                 {
  699.                                 window_mask  = 1L << data->win->UserPort->mp_SigBit;
  700.                                 }
  701.                                 else return(set);
  702.                                 setBase(data);
  703.                             }
  704.                             break;
  705.                         case    test_getwin:
  706.                             test_msg->posx=data->win->LeftEdge;
  707.                             test_msg->posy=data->win->TopEdge;
  708.                             test_msg->sizx=data->win->Width;
  709.                             break;
  710.                         }
  711.                         ReplyMsg((struct Message *)test_msg);
  712.                     }
  713.                     }
  714.                     if(data->scrnot)
  715.                     {
  716.                     if (sigs & my_noti_port_mask)
  717.                     {
  718.                         struct ScreenNotifyMessage  *snm;
  719.                         while(snm = (struct ScreenNotifyMessage *) GetMsg(my_noti_port))
  720.                         {
  721.                         switch(snm->snm_Type)
  722.                         {
  723.                             case    SCREENNOTIFY_TYPE_CLOSESCREEN:
  724.                                 running=FALSE;
  725.                                 break;
  726.                             case    SCREENNOTIFY_TYPE_WORKBENCH:
  727.                                 if((ULONG)snm->snm_Value)
  728.                                 {
  729.                                 if(closed)
  730.                                 {
  731.                                     Delay(50L);
  732.                                     if(openWindow(set,data,gclass,lclass))
  733.                                     {
  734.                                     window_mask  = 1L << data->win->UserPort->mp_SigBit;
  735.                                     closed=FALSE;
  736.                                     }
  737.                                     else running=FALSE;
  738.                                     setBase(data);
  739.                                 }
  740.                                 }
  741.                                 else
  742.                                 {
  743.                                 if(!closed)
  744.                                 {
  745.                                     closeWindow(set,data);
  746.                                     closed=TRUE;
  747.                                 }
  748.                                 first_run=TRUE;
  749.                                 }
  750.                                 break;
  751.                         }
  752.                         ReplyMsg((struct Message *) snm);
  753.                         }
  754.                     }
  755.                     }
  756.                 }
  757.                 EndNotify(notifyrequest);
  758.                 }
  759.                 else show(err_nosta);
  760.                 FreeSignal(not_sig);
  761.             }
  762.             else show(err_nosta);
  763.             pFreeVec((ULONG *)notifyrequest);
  764.             }
  765.             else show(err_nomem);
  766.             if(!CheckIO((struct IORequest *)my_time_request_clock))
  767.             AbortIO((struct IORequest *)my_time_request_clock);
  768.             WaitIO((struct IORequest *)my_time_request_clock);
  769.             CloseDevice((struct IORequest *)my_time_request_clock);
  770.         }
  771.         else show(err_nodev);
  772.         DeleteIORequest((struct IORequest *)my_time_request_clock);
  773.         }
  774.         else show(err_nopor);
  775.         DeleteMsgPort((struct MsgPort *)my_time_port_clock);
  776.     }
  777.     else show(err_nopor);
  778.     DeletePort(my_test_port);
  779.     }
  780.     else show(err_nopor);
  781.     if(data->scrnot)
  782.     {
  783.     if((!data->on_public)|(!strcmp(&set->pub_name[0],"Workbench")))
  784.         while(!RemWorkbenchClient((APTR)my_handler)) Delay(10);
  785.     else
  786.         while(!RemCloseScreenClient((APTR)my_handler)) Delay(10);
  787.     DeleteMsgPort(my_noti_port);
  788.     }
  789.     return(set);
  790. }
  791.  
  792.